<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll">
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      v-model="text"
      @keydown.enter="addfn"
    />
  </header>
</template>

<script>
import {mapGetters, mapMutations} from 'vuex'
export default {
 data(){
   return {
    text:'',
   }
  },
  computed:{
  ...mapGetters(['addList']),
    isAll:{
    set(checked){
      this['add/selectAll'](checked)
    },
    get(){
    return this.addList.every(item => item.isDone === true)
    }
    }
  },
  methods:{
  ...mapMutations(['add/selectAll']),
    addfn(){
    this.$store.commit('add/addlist',this.text)
    this.text = ''
    }
  }
}
</script>
